package com.java.day4collection;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;


public class SortDemo {

    public static void main(String[] args) {
        Iterator a;
        Scanner scanner = new Scanner(System.in);
        List<Person> persons = new ArrayList<>();
        persons.add(new Person(1,"zhangsan",30,"男"));
        persons.add(new Person(2,"lisi",20,"男"));
        persons.add(new Person(3,"liwu",35,"女"));
        persons.add(new Person(5,"maliu",40,"女"));
        persons.add(new Person(4,"zhouqi",50,"男"));

        List<Person> result = persons.stream()
                //对集合进行筛选
                .filter((p) -> p.getGender().equals("男"))
                .filter((p) -> p.getAge() > 25)
                //对数据进行转换
                .map((p) -> {p.setAge(p.getAge() + 2); return p;})
                //收集筛选后的数据
                .collect(Collectors.toList());

        result.forEach((p) -> System.out.println(p));

//        //排序
////        Collections.sort(persons);
//        System.out.println("请选择排序方式：1、按编号排序 2、按年龄排序 3、按姓名排序");
//        int op = scanner.nextInt();
//        switch (op){
//            case 1:
//                //传入不同的比较器对象，就可以指定不同的排序方式
////                Collections.sort(persons,new IdComparator());
////                Collections.sort(persons, new Comparator<Person>() {
////                    @Override
////                    public int compare(Person o1, Person o2) {
////                        return o1.getId() - o2.getId();
////                    }
////                });
//                Collections.sort(persons,(p1,p2) -> p1.getId() - p2.getId());
//                break;
//            case 2:
////                Collections.sort(persons,new AgeComparator());
//                Collections.sort(persons,(p1,p2) -> p1.getAge() - p2.getAge());
//                break;
//            case 3:
////                Collections.sort(persons,new NameComparator());
//                Collections.sort(persons,(p1,p2) -> p1.getName().compareTo(p2.getName()));
//                break;
//            default:
//                System.out.println("输入错误");
//        }
////        for(Person p : persons){
////            System.out.println(p);
////        }
//        persons.forEach((o) -> System.out.println(o));
    }
}
